﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using xn;

namespace StartDance
{
    public class Player
    {
        public Point3D position;
        public uint uid;
        public const int KINECT_DISTANCE = 1200;
        public int kSize = 250;      //500mm
        public int score = 0;

        public Player(uint _uid)
        {
            uid = _uid;
        }

        /// <summary>
        /// Mendapatkan posisi kuadran pemain
        ///  Kinect
        /// 1  2  3
        /// 4  5  6
        /// 7  8  9
        /// </summary>
        /// <returns></returns>
        public Direction getKuadran() 
        {
            int kX, kZ;
            if (position.X > -1.5 * kSize && position.X < -0.5 * kSize) kX = 1;
            else if (position.X > -0.5 * kSize && position.X < 0.5 * kSize) kX = 2;
            else if (position.X > 0.5 * kSize && position.X < 1.5 * kSize) kX = 3;
            else kX = -1000;

            if (position.Z > KINECT_DISTANCE - kSize && position.Z < KINECT_DISTANCE) kZ = 0;
            else if (position.Z > KINECT_DISTANCE && position.Z < KINECT_DISTANCE + kSize) kZ = 1;
            else if (position.Z > KINECT_DISTANCE + kSize && position.Z < KINECT_DISTANCE + 2 * kSize) kZ = 2;
            else kZ = -1000;

            Direction dir;
            if (kX == 2 && kZ == 0) dir = Direction.Up;
            else if (kX == 1 && kZ == 1) dir = Direction.Left;
            else if (kX == 3 && kZ == 1) dir = Direction.Right;
            else if (kX == 2 && kZ == 2) dir = Direction.Down;
            else if (kX == 1 && kZ == 0) dir = Direction.LeftUp;
            else if (kX == 1 && kZ == 2) dir = Direction.LeftDown;
            else if (kX == 3 && kZ == 0) dir = Direction.RightUp;
            else if (kX == 3 && kZ == 2) dir = Direction.RightDown;
            else if (kX == 2 && kZ == 1) dir = Direction.Center;
            else dir = Direction.None;

            return dir;
        }
    }
}
